using System;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using Castle.Facilities.Logging;
using Castle.Model.Configuration;
using log4net;

namespace BEGDC.Utility.Castle
{
	public class AppContainer : WindsorContainer
	{
		private static readonly ILog log = LogManager.GetLogger( typeof(AppContainer) );
		private static AppContainer instance;

		public static AppContainer Instance
		{
			get
			{
				if (instance == null)
				{
					instance = new AppContainer();
				}
				return instance; 
			}
		}

		public AppContainer() : this(new XmlInterpreter(new EncryptFileResource("AppContainer.xml")))
		{
            			
		}

		public AppContainer(XmlInterpreter interpreter) : base(interpreter)
		{
			Init();
		}

		private void Init()
		{
			RegisterFacilities();
		}

		private void RegisterFacilities()
		{
//			AddFacility("nhibernate", new NHibernateFacility());
//			AddFacility("transactions", new TransactionFacility());

			//init logging
			//MutableConfiguration confignode = new MutableConfiguration("facility");

			//confignode.Attributes.Add("loggingApi", LoggerImplementation.Log4net.ToString());
			//confignode.Attributes.Add("customLoggerFactory", String.Empty);

			//this.Kernel.ConfigurationStore.AddFacilityConfiguration("logging", confignode);

			//AddFacility("logging", new LoggingFacility());
		}
	}
}
